<include file="public@header">
<body>
    <div class="indexbg headhead">
        <form action="" method="post" class="layui-form">
        <h3 class="mytitle" style="position: relative;left: -0.4rem;">{:lang('Fund password')}</h3>
        <div class="infshowall">
            <div class="rpass">
                <p>{:lang('Login password')}</p>
                <div class="rpassdiv">
                    <input type="text" name="login_password" placeholder="{:lang('Please enter your password')}">
                    <img src="__STATIC__/hybit/images/look.png" alt="" data-type="look" onclick="is_password(this)">
                    <img src="__STATIC__/hybit/images/nolook.png" alt="" data-type="nolook" onclick="is_password(this)">
                </div>
            </div>
            <div class="rpass">
                <p>{:lang('New fund password')}</p>
                <div class="rpassdiv">
                    <input type="text" name="password" placeholder="{:lang('Please enter the new fund password')}">
                    <img src="__STATIC__/hybit/images/look.png" alt="" data-type="look" onclick="is_password(this)">
                    <img src="__STATIC__/hybit/images/nolook.png" alt="" data-type="nolook" onclick="is_password(this)">
                </div>
            </div>
            <div class="rpass">
                <p>{:lang('Confirm fund password')}</p>
                <div class="rpassdiv">
                    <input type="text" name="repassword" placeholder="{:lang('Please enter it again')}">
                    <img src="__STATIC__/hybit/images/look.png" alt="" data-type="look" onclick="is_password(this)">
                    <img src="__STATIC__/hybit/images/nolook.png" alt="" data-type="nolook" onclick="is_password(this)">
                </div>
            </div>
            <div class="rpass">
                <p>{:lang('Mobile')}/{:lang('Email')}</p>
                <div class="rpassdiv">
                    <input type="text" name="username" value="<if $user.mobile>{$user.mobile}<else/>{$user.user_email}</if>" readonly>
                </div>
            </div>
            <div class="rpass">
                <p>{:lang('Code')}</p>
                <div class="rpassdiv">
                    <input type="text" name="code" placeholder="{:lang('Please Enter code')}">
                    <button type="button" class="infyzmbtn">{:lang('Get code')}</button>
                </div>
            </div>
        </div>
        <button class="emailbtn" style="position: fixed;" lay-submit>{:lang('Submit')}</button>
        </form>
    </div>
    
    <script src="__STATIC__/hybit/js/jquery.min.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <script>
        layui.use(['form','layer'],function(){
            var layer = layui.layer,
                form = layui.form;

            $('.infyzmbtn').click(function(){
                var username = $('input[name=username]').val();
                var obj = $(this);
                $.ajax({
                    type: 'get',
                    url: '{:url("user/VerificationCode/send")}',
                    data: {username:username,act:1},
                    success:function(res){
                        layer.msg(res.msg)
                        if(res.code == 1){
                            let count = 60;
                            const countDown = setInterval(() => {
                            if (count === 0) {
                            $(obj).text('{:lang("Resend")}').removeAttr('disabled');
                            clearInterval(countDown);
                            } else {
                               $(obj).attr('disabled', true);
                               $(obj).text(count + 's');
                            }
                            count--;
                            }, 1000);
                        }
                    }
                });
            });

            //监听提交
            form.on('submit', function(data){
                var _this = $(this);
                _this.attr("disabled",true);
                $.ajax({
                    type: 'post',
                    url: '{:url("user/profile/capital_password")}',
                    data: data.field,
                    success:function(res){
                        layer.msg(res.msg)
                        if(res.code == 1){
                            setTimeout(function(){ window.history.go(-1); }, 1500);
                        }else{
                            _this.removeAttr("disabled");
                        }
                    }
                });
                return false;
            });
        });

        function is_password(obj){
            let $this = $(obj);
            let type = $this.attr('data-type');
            if(type == 'look'){
                $this.siblings('img').show();
                $this.hide();
                $this.siblings('input').attr('type','password');
            }else{
                $this.siblings('img').show();
                $this.hide();
                $this.siblings('input').attr('type','text');
            }
        }
    </script>
</body>
</html>